package tagdb.ui;

import com.jgoodies.forms.layout.CellConstraints;
import org.jfree.chart.ChartPanel;
import tagdb.model.DenovoSearchResult;
import tagdb.model.TagSearchResult;
import tagdb.ui.stats.DenovoScoreHistogram;
import tagdb.ui.stats.TagSearchScoreHistogram;

import javax.swing.*;
import java.awt.*;

public class StatsPanel extends JPanel {

    /**
     * The d novo stats panel.
     */
    private ChartPanel denovoStatsPnl;

    /**
     * The tag search stats panel.
     */
    private ChartPanel tagSearchStatsPnl;

    /**
     * Tabbed pane for different statistics.
     */
    private JTabbedPane statsPane;
    private JPanel statsPnl1;
    private JPanel statsPnl2;

    /**
     * Constructs a basic statistics panel.
     */
    public StatsPanel() {
        initComponents();
    }

    /**
     * Initialize the components.
     */
    private void initComponents() {
        CellConstraints cc = new CellConstraints();

        statsPane = new JTabbedPane();
        statsPane = new JTabbedPane(JTabbedPane.TOP, JTabbedPane.WRAP_TAB_LAYOUT);
        denovoStatsPnl = new ChartPanel(null);
        statsPnl1 = new JPanel(new BorderLayout());
        statsPnl2 = new JPanel(new BorderLayout());
        statsPane.addTab("De Novo Search", statsPnl1);
        statsPane.addTab("Database Search", statsPnl2);

        //statsPane.addTab("Database Search", searchIcon, mainPnl);
        this.setLayout(new BorderLayout());
        this.add(statsPane, BorderLayout.NORTH);
    }

    /**
     * This method updates the results in the panel.
     * 
     * @param denovoSearchResult
     */
    public void updateDenovoResults(DenovoSearchResult denovoSearchResult) {
        DenovoScoreHistogram hist = new DenovoScoreHistogram(denovoSearchResult);
        CellConstraints cc = new CellConstraints();
        denovoStatsPnl = new ChartPanel(hist.getChart());
        statsPnl1.add(denovoStatsPnl, BorderLayout.CENTER);
        statsPnl1.repaint();
        this.repaint();
    }

    /**
     * This method updates the results in the panel.
     *
     * @param tagSearchResult TagSearchResult
     */
    public void updateTagSearchResults(TagSearchResult tagSearchResult) {
        //TODO: Add flag for target decoy
        TagSearchScoreHistogram hist = new TagSearchScoreHistogram(tagSearchResult);
        CellConstraints cc = new CellConstraints();
        tagSearchStatsPnl = new ChartPanel(hist.getChart());
        statsPnl2.add(tagSearchStatsPnl, BorderLayout.CENTER);
        statsPnl2.repaint();
        this.repaint();
    }
}
